<?php


namespace App\Repositories\Lottery;

use App\Traits\Singleton;
use App\Models\MainDB\Lottery\Setting as Model;

class SettingRepository
{
    use Singleton;

    public function one(array $condition = [], bool $fail = false, bool $lock = false)
    {
        $query = Model::query();
        $query->where($condition);
        if ($lock) {
            $query->lockForUpdate();
        }
        return $fail == true ? $query->firstOrFail() : $query->first();
    }

    public function find(int $id, bool $lock = false)
    {
        return $this->one(['id' => $id], true, $lock);
    }

    public function create(array $data)
    {
        $model = new Model();
        $model->fill($data);
        $model->save();
        $model->refresh();

        return $model;
    }

}